proc MAGELLAN__hexToRGB {hex} {
	if { [catch { set R [string range [expr "0x[string range $hex 0 1]/255."] 0 6 ]
	set G [string range [expr "0x[string range $hex 2 3]/255."] 0 6 ]
	set B [string range [expr "0x[string range $hex 4 5]/255."] 0 6 ] 	} ]} {
		 return [list [expr rand()] [expr rand()] [expr rand()] [expr rand()] ]
	}
	return [list $R $G $B 1]
}


proc MAGELLAN__InitColor {type nb} {

	if {![file exists temp.xml]} {
		puts "Accessing kuler-api.adobe.com"
	  http::geturl "http://kuler-api.adobe.com//feeds/rss/get.cfm?timeSpan=10&listType=${type}&itemsPerPage=$nb" -channel [open temp.xml w]
	 }
	puts "done"
	set L_L_color [list]
	set txt [read [open temp.xml r]]
	set next_is_a_color 0
	foreach line [split $txt "\n"] {
		
		if {[string first "Hex:" $line] >= 0} {
			set next_is_a_color 1
			continue
		}
	
		if {$next_is_a_color} {
		    set pos  [string first "<" $line]
			set line [string range $line 0 ${pos}-1]
		    
			set L_color [list]
			foreach hex_color [split $line ","] {
			  lappend L_color [MAGELLAN__hexToRGB [string trim $hex_color]]
			 }
			
			if {[llength $L_color] == 5} {lappend L_L_color $L_color}
		}
		
		set next_is_a_color 0
	}
	return $L_L_color
}